<template>
	<view class="page">
		<view class="nav d_flex_b">
			<view :class="i==curNav?'item ac':'item'" v-for="(item,i) in navList" :key="item.name" @click="changeNav(i)">
				<view class="name">{{item.name}}</view>
				<view class="val">({{item.num}})</view>
			</view>
		</view>
		<view class="content">
			<view class="item d_flex_b" v-for="(item,i) in navList[curNav].data" :key="i" @click="">
				<view class="word">{{item.name}}</view>
				<view class="mean" v-if="item.wordExplain">{{JSON.parse(item.wordExplain)[0].chinExplain}}</view>
			</view>
		</view>
		<view class="page-btn">
			<view class="btn" @click="toStart">快闪</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navList:[
					{name:'未学习',num:0,type:4,position:0,data:[],offset:0},
					{name:'错词',num:0,type:5,position:0,data:[],offset:0},
					{name:'已掌握',num:0,type:3,position:0,data:[],offset:0},
				],
				curNav:0,
				wordData:'',
				limit:10,
			};
		},
		onShow() {
			this.navList[this.curNav].data.page=1;
			this.getData();
		},
		onReachBottom() {
			if(this.navList[this.curNav].data.length<this.navList[this.curNav].num){
				this.navList[this.curNav].offset+=10;
				this.getList();
			}
		},
		methods:{
			changeNav(i){
				this.curNav=i;
				this.getList();
			},
			toStart(){
				let curData=this.navList[this.curNav];
        if (!curData.num) {
          uni.showToast({
            icon: 'none',
            title: `${curData.name}的数量为${curData.num}`
          })
          return
        }
				uni.navigateTo({
					url:'/pages/quick/conduct?type='+curData.type+'&position='+curData.position+'&total='+curData.num
				})
			},
			getData(){
				this.$http.get1('api/client/word/queryWordQuickShot').then(res=>{
					if(res.code==200){
						this.wordData=res.data;
						this.navList[0].num=this.wordData.wordTotal-this.wordData.allGraspWord
						this.navList[1].num=this.wordData.errorWord
						this.navList[2].num=this.wordData.allGraspWord
						res.data.position.map(val=>{
							if(val.type==3){
								this.navList[2].position=val.position||0
							}
							if(val.type==4){
								this.navList[0].position=val.position||0
							}
							if(val.type==5){
								this.navList[1].position=val.position||0
							}
						})
						this.getList();
					}
				})
			},
			getList(){
				this.$http.get1('api/client/word/quickShotWord',{
					type:this.navList[this.curNav].type,
					offset:this.navList[this.curNav].offset,
					limit:this.limit
				}).then(res=>{
					console.log(res);
					if(res.code==200){
						if(this.navList[this.curNav].offset==0){
							this.navList[this.curNav].data=res.data;
						}else{
							this.navList[this.curNav].data.push(...res.data);
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #F2F3F8;
}
.page{
	padding:120rpx 30rpx 200rpx ;
	box-sizing: border-box;
}
.nav{
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 96rpx;
	z-index: 9;
	background-color: #fff;
	.item{
		flex: 1;
		height: 100%;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		border-bottom: 4rpx solid #fff;
		color: #575A64;
		.name{
			font-size: 28rpx;
			font-weight: 600;
		}
		.val{
			font-size: 20rpx;
			margin-top: 4rpx;
		}
		&.ac{
			border-bottom: 4rpx solid #5480F8;
			color: #5480F8;
		}
	}
}
.content{
	.item{
		width: 100%;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42,65,152,0.05);
		border-radius: 20rpx ;
		margin-bottom: 20rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		.word{
			width: 300rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #333333;
		}
		.mean{
			flex: 1;
			width: 350rpx;
			margin-left: 10rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 24rpx;
			color: #575A64;
		}
	}
}
.page-btn{
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 176rpx;
	padding: 30rpx 62rpx;
	box-sizing: border-box;
	background-color: #fff;
	z-index: 10;
	.btn{
		width: 100%;
		height: 90rpx;
		background: #5480F8;
		border-radius: 46rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 32rpx;
		font-weight: 500;
		color: #FFFFFF;
		&.disable{
			background-color: #CAD8FC;
		}
	}
}

</style>
